from django.core.paginator import Paginator
from rest_framework.pagination import  PageNumberPagination as DRFPageNumberPagination
from buyHigh.utils.buyHighResponse import APIResponse


class PageNumberPagination(DRFPageNumberPagination):
    page_size = 4  # 每页的数据量（默认）
    page_query_param = "page"  # 请求参数中的 page参数名
    page_size_query_param = None  # 不接受前端传递的page_size参数，后端返回固定的数量

    def get_paginated_response(self, data):
        # 自定义响应格式
        return APIResponse(
        next= self.get_next_link(),
        previous= self.get_previous_link(),
        count= self.page.paginator.count,
        data=data
        )